﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
   public class AcoutBkDAL
    {
        DBHelper db = new DBHelper();
        public List<AcoutBk> GetlistALL()
        {
            List<AcoutBk> list = null;
            string sql = $"select AccountID, AccountName, AccountPwd, AccountSex, AccountAge, AccountPhone, AccountAddres, Mailbox from [dbo].[AcoutBk]";
            DataTable dt = db.GetData(sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                list = new List<AcoutBk>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    AcoutBk info = new AcoutBk();
                    info.AccountID = Convert.ToInt32(dt.Rows[i]["AccountID"].ToString());
                    info.AccountName = dt.Rows[i]["AccountName"].ToString();
                    info.AccountPwd = dt.Rows[i]["AccountPwd"].ToString();
                    info.AccountSex = dt.Rows[i]["AccountSex"].ToString();
                    info.AccountAge = dt.Rows[i]["AccountAge"].ToString();
                    info.AccountAddres = dt.Rows[i]["AccountAddres"].ToString();
                    info.AccountPhone = dt.Rows[i]["AccountPhone"].ToString();
                    info.Mailbox = dt.Rows[i]["Mailbox"].ToString();
                    list.Add(info);
                }
            }
            return list;
        }
        public bool AddDer(AcoutBk acoutBk) {
            string sql =$"insert into [dbo].[AcoutBk](AccountName,AccountPhone, AccountAddres, Mailbox)values('{acoutBk.AccountName}','{acoutBk.AccountPhone}','{acoutBk.AccountAddres}','{acoutBk.Mailbox}')";
            bool result = true;
            if (db.SetData(sql))
            {
                result = false;
            }
            return result;
        }
    }
}
